home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / kr_art.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  8KB  |  335 lines

  1. /*****************************************************************************
  2.   FILE           : kr_art.c
  3.   SHORTNAME      : 
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS Kernel Functions for ART networks
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Kai-Uwe Herrmann
  10.   DATE           : 17.05.92
  11.  
  12.   CHANGED BY     : Sven Doering
  13.   IDENTIFICATION : @(#)kr_art.c    1.7 3/15/94
  14.   SCCS VERSION   : 1.7
  15.   LAST CHANGE    : 3/15/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #include <stdlib.h>
  21.  
  22. #ifndef NULL /* if NULL pointer is not defined include stdio.h */
  23. #include <stdio.h>
  24. #endif
  25.  
  26. #include "krart_df.h"   /*  Definitions for ART networks */
  27.  
  28. #include "kr_const.h"
  29. #include "kr_mac.h"
  30. #include "kr_def.h"
  31. #include "kr_typ.h"
  32. #include "kr_funcs.h"
  33. #include "kernel.h"
  34. #include "glob_typ.h"
  35. #include "kr_art.ph"
  36.  
  37. /* declaration of module functions
  38. */
  39.  
  40. /**************** functions, visible to other modules **************************/
  41.  
  42. /*#################################################
  43.  
  44. GROUP: ART kernel functions
  45.        by Kai-Uwe Herrmann
  46.  
  47. #################################################*/
  48.  
  49.  
  50.  
  51. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  52. /* initialization of activations of all input units according to their i_act
  53.    value. this initialization is necessary each time a new pattern is
  54.    presented to the network.
  55. */
  56.  
  57. krui_err krart_reset_activations (void)
  58. {
  59.    krui_err        ret_code = KRERR_NO_ERROR;
  60.  
  61.    struct Unit     *unit_ptr;
  62.  
  63.  
  64.    FOR_ALL_UNITS (unit_ptr) {
  65.  
  66.       if (! IS_INPUT_UNIT (unit_ptr)) {
  67.          unit_ptr->act = unit_ptr->i_act;
  68.       } /*if*/
  69.  
  70.       /* The output is set for input units, too
  71.       */
  72.       unit_ptr->Out.output = unit_ptr->act;
  73.  
  74.    } /*FOR_ALL_UNITS*/
  75.  
  76.    return (ret_code);
  77.  
  78. } /* krart_reset_activations () */
  79. /*___________________________________________________________________________*/
  80.  
  81.  
  82.  
  83.  
  84.  
  85. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  86. /* synchronous propagation (1 cycle) i.e. each unit puts its output onto
  87.    its outgoing links and calculates its new activation.
  88. */
  89. void  krart_prop_synch (void)
  90. {
  91.   struct Unit    *unit_ptr;
  92.  
  93.   /* calculate new activations of non input units
  94.   */
  95.  
  96.   FOR_ALL_UNITS (unit_ptr) {
  97.  
  98.      if (!IS_INPUT_UNIT(unit_ptr)) {
  99.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  100.      } /*if*/
  101.  
  102.   } /*FOR_ALL_UNITS*/
  103.  
  104.   /* set new output values
  105.   */
  106.  
  107.   FOR_ALL_UNITS (unit_ptr) {
  108.  
  109.      if (unit_ptr->out_func == OUT_IDENTITY) {
  110.         unit_ptr->Out.output = unit_ptr->act;
  111.      } else {
  112.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  113.      } /*if*/
  114.  
  115.   } /*FOR_ALL_UNITS*/
  116.  
  117. } /* krart_prop_synch */
  118. /*___________________________________________________________________________*/
  119.  
  120.  
  121.  
  122.  
  123. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  124. /* get the winner of the last propagation cycle. returns a pointer to
  125.    the winning recognition unit.
  126. */
  127. struct Unit  *krart_get_winner (TopoPtrArray wta_layer, FlintType winner_output)
  128.                             /* points to first pointer to recognition unit
  129.                             */
  130.                                 /* output value of the winning unit */
  131.  
  132. {
  133.    TopoPtrArray   topo_ptr;
  134.  
  135.    struct Unit    *unit_ptr,
  136.                   *winner_ptr = NULL;  /* points to the unit with the maximal
  137.                                           activation
  138.                                        */
  139.  
  140.    FlintType      max_out  = 0.0;      /* contains the maximal activation
  141.                                        */
  142.  
  143.  
  144.    topo_ptr = wta_layer;
  145.  
  146.    while ((unit_ptr = *topo_ptr++) != NULL) {
  147.  
  148.       if (unit_ptr->Out.output > max_out) {
  149.          max_out    = unit_ptr->Out.output;
  150.          winner_ptr = unit_ptr;
  151.          continue;
  152.       } /*if*/
  153.  
  154.       /* The foollowing statements assure, that a winner is returned, if
  155.          no Reset signal is sent from Reset general unit. So we will
  156.          find a winner, even if the winner unit's activation is 0.0
  157.          This is neccessary to assure, that all recognition units are
  158.          tested for to get a 'not classifiable' signal when all and really
  159.          all local reset units are turned on.
  160.       */
  161.       if ((winner_ptr == NULL) && (unit_ptr->Out.output >= max_out)) {
  162.          max_out    = unit_ptr->Out.output;
  163.          winner_ptr = unit_ptr;
  164.       } /*if*/
  165.  
  166.    } /*while*/
  167.  
  168.  
  169.  
  170.    /* set activation and output of winner unit to 1.0, the one of the
  171.       other recognition units to 0.0
  172.    */
  173.  
  174.    topo_ptr = wta_layer;
  175.  
  176.    while ((unit_ptr = *topo_ptr++) != NULL) {
  177.  
  178.       if (unit_ptr != winner_ptr) {
  179.          unit_ptr->Out.output = 0.0;
  180.       } else {
  181.          unit_ptr->Out.output = winner_output;
  182.       } /*if*/
  183.  
  184.    } /*while*/
  185.  
  186.  
  187.    return (winner_ptr);
  188.  
  189. } /* krart_get__winner () */
  190. /*___________________________________________________________________________*/
  191.  
  192.  
  193.  
  194.  
  195.  
  196. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  197. void  krart_deleteTouchFlags (void)
  198. {
  199.    register struct Unit *unit_ptr;
  200.  
  201.    FOR_ALL_UNITS (unit_ptr) {
  202.  
  203.       /* delete touch flags
  204.       */
  205.       unit_ptr->flags &= ~UFLAG_REFRESH;
  206.  
  207.    } /*FOR_ALL_UNITS*/
  208.  
  209. } /* krart_deleteTouchFlags () */
  210. /*___________________________________________________________________________*/
  211.  
  212.  
  213.  
  214.  
  215.  
  216. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  217. void  krart_init_sorting (void)
  218. {
  219.    register struct Unit *unit_ptr;
  220.  
  221.  
  222.    krart_deleteTouchFlags ();
  223.  
  224.    FOR_ALL_UNITS (unit_ptr) {
  225.  
  226.       /* init lln and lun
  227.       */
  228.       unit_ptr->lln = unit_ptr->lun = 0;
  229.  
  230.    } /*FOR_ALL_UNITS*/
  231.  
  232. } /* krart_init_sorting () */
  233. /*___________________________________________________________________________*/
  234.  
  235.  
  236.  
  237. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  238. int  krart_get_NoOfInputUnits (void)
  239. {
  240.    register struct Unit  *unit_ptr;
  241.    int                   count           = 0;
  242.  
  243.  
  244.    FOR_ALL_UNITS (unit_ptr) {
  245.  
  246.       if (IS_INPUT_UNIT(unit_ptr)) {
  247.          count++;
  248.       } /*if*/
  249.  
  250.    } /*FOR_ALL_UNITS*/
  251.  
  252.    return (count);
  253.  
  254.  
  255. } /* krart_get_NoOfInputUnits () */
  256. /*___________________________________________________________________________*/
  257.  
  258.  
  259.  
  260.  
  261. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  262. bool   krart_check_undeterminedUnits (void)
  263. {
  264.    register struct Unit   *unit_ptr;
  265.  
  266.    FOR_ALL_UNITS (unit_ptr) {
  267.  
  268.       if (unit_ptr->lln == 0) {
  269.          TOPO_MSG_UNDETERMINED_UNIT (unit_ptr);
  270.          return (TRUE);
  271.       } /*if*/
  272.  
  273.    } /*FOR_ALL_UNITS*/
  274.  
  275.    return (FALSE);
  276.  
  277. } /* krart_check_undeterminedUnits () */
  278. /*___________________________________________________________________________*/
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  287. void  krart_save_inp_pat (TopoPtrArray topo_inp_ptr)
  288. {
  289.   TopoPtrArray   topo_ptr = topo_inp_ptr;
  290.  
  291.   while (*topo_ptr != NULL) {
  292.      if (IS_INPUT_UNIT (*topo_ptr)) {
  293.         (*topo_ptr)->value_a = (*topo_ptr)->act;
  294.      } /*if*/
  295.      topo_ptr++;
  296.   } /*while*/
  297.   return;
  298. } /* krart_save_inp_pat () */
  299. /*___________________________________________________________________________*/
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  307. bool  krart_inp_pat_changed (TopoPtrArray topo_inp_ptr)
  308. {
  309.  
  310.    TopoPtrArray    topo_ptr = topo_inp_ptr;
  311.  
  312.    while (*topo_ptr != NULL) {
  313.       if ((IS_INPUT_UNIT(*topo_ptr)) && ((*topo_ptr)->value_a != (*topo_ptr)->act)) {
  314.          return (TRUE);
  315.       } /*if*/
  316.       topo_ptr++;
  317.    } /*FOR_ALL_UNITS*/
  318.  
  319.    return (FALSE);
  320. } /* krart_inp_pat_changed () */
  321. /*___________________________________________________________________________*/
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.